<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/1/22
  Time: 16:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%--    http://localhost/atcrowdfunding/index.jsp--%>
    <base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
    <script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btn1").click(function () {
                let array = new Array(5, 8, 12)
                $.ajax({
                    url: "send/array/one.html",
                    type: "post",
                    data: {
                        array: array
                    },
                    dataType: "text",
                    success: function (response) {
                        alert(response)
                    },
                    error: function (response) {
                        console.log(response)
                    }
                })
            });
            $("#btn2").click(function () {
                $.ajax({
                    url: "send/array/two.html",
                    type: "post",
                    data: {
                        "array[0]": 5,
                        "array[1]": 8,
                        "array[2]": 12,

                    },
                    dataType: "text",
                    success: function (response) {
                        alert(response)
                    },
                    error: function (response) {
                        console.log(response)
                    }
                })
            });
            $("#btn3").click(function () {
                let array = [5, 8, 12]
                console.log(array, array.length)
                //将SON数组转换为JSON字符串
                let requestBody = JSON.stringify(array);
                console.log(requestBody)
                $.ajax({
                    url: "send/array/three.html",
                    type: "post",
                    contentType: "application/json;charset=UTF-8",//设置请求体得内容类型
                    data: requestBody,  //请求体
                    dataType: "text",
                    success: function (response) {
                        alert(response)
                    },
                    error: function (response) {
                        console.log(response)
                    }
                })
            });
            $("#btn4").click(function () {
                // 准备要发送的数据
                let student = {
                    "stuId": 5,
                    "stuName": "tom",
                    "address": {
                        "province": "广东",
                        "city": "深圳",
                        "street": "后瑞"
                    },
                    "subjectList": [
                        {
                            "subjectName": "JavaSE",
                            "subjectScore": 100
                        }, {
                            "subjectName": "SSM",
                            "subjectScore": 99
                        }
                    ],
                    "map": {
                        "k1": "v1",
                        "k2": "v2"
                    }
                };
                let studentInfo = JSON.stringify(student);
                $.ajax({
                    url: "send/compose/object.json",
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=UTF-8",
                    data: studentInfo,
                    success: function (response) {
                        console.log(response)
                    },
                    error: function (response) {
                        console.log(response)
                    }
                })
            });
            $("#btn5").click(function () {
                layer.msg("这里是 layer 弹出的消息！");
            })
        })
    </script>l
</head>
<body>
<%--以斜杠开头不参考base标签--%>
<a href="test/ssm.html">测试ssm整合环境</a>
<br>
<button id="btn1">Send [5,8,12] One</button>
<br>
<button id="btn2">Send [5,8,12] Two</button>
<br>
<button id="btn3">Send [5,8,12] Three</button>
<br>
<button id="btn4">Send StudentInfo</button>
<button id="btn5">点我 弹框</button>
</body>
</html>
